/**
 * @file
 * @author dousha 
 * @date 2020/11/28.
 */

#ifndef CRYPTSTICK_SERIAL_STATE_MACHINE_H
#define CRYPTSTICK_SERIAL_STATE_MACHINE_H

#include <stddef.h>
#include <stdint.h>
#include <stm32f1xx_hal.h>

#define WAIT_PREAMBLE 0
#define WAIT_CS 1
#define WAIT_LENGTH 2
#define WAIT_DATA 3
#define WAIT_PARAMETER 4
#define WAIT_MULTIPART_LENGTH 5
#define WAIT_MULTIPART_DATA 6
#define WAIT_UNLOCK 255

#define FUNCTION_NOP 0
#define FUNCTION_SM3 1
#define FUNCTION_SM4_ENCRYPT 2
#define FUNCTION_SM4_KEY_GEN 3
#define FUNCTION_SM4_DECRYPT 4
#define FUNCTION_EEPROM_INSPECT 5
#define FUNCTION_SECRET_STORE 6
#define FUNCTION_SECRET_READ 7
#define FUNCTION_HMAC 8
#define FUNCTION_SM2 10

#define SM4_PARAM_USE_MASTER_SECRET 0x00u
#define SM4_PARAM_USE_PROVIDED_KEY  0x01u

extern size_t serial_state_machine_handle_input(const uint8_t *);

#endif //CRYPTSTICK_SERIAL_STATE_MACHINE_H
